//
//  node.c
//  ShannonFano
//
//  Created by Alessio Scannapieco on 18.11.11.
//  Copyright 2011 SUPSI - Manno. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include "node.h"

/***********************************************************************************************************************/
/*                                          Funzioni interne                                                           */
/***********************************************************************************************************************/
void padding (char ch, int n);
/***********************************************************************************************************************/

void padding (char ch, int n) {
    int i;
    
    for (i = 0; i<n; i++) {
        putchar(ch);
    }
}

void printBinaryTree (Node *root, int level) {    
    if (root == NULL) {
        padding( '\t', level);
        puts ( "   ~" );
    }
    else {
        printBinaryTree(root->right, level+1);
        padding ( '\t', level);
        if (root->valueASCII == 64) {
            printf ( "%c\n", root->valueASCII);
        } else {
            printf ( "%c (%d, %lu)\n", root->valueASCII, root->valueASCII, root->count);
        }
        printBinaryTree(root->left, level+1);
    }
}